package com.snsoft.kidstube;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
import android.widget.Toast;
import android.net.NetworkInfo;

public class SplashActivity extends Activity 
{
	public boolean cf = true;

	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	super.onCreate(savedInstanceState); 
        setContentView(R.layout.splash);
        
        Handler hd = new Handler();
        
        // Network connected confirm
        ConnectivityManager con =  (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        
        if (con.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED
        || con.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING
        || con.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED 
        || con.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
        {
        	cf = true;
        	
        	hd.postDelayed(new splashHandler(), 2000);
        }
        else
        {
        	cf = false;
        	
        	Toast.makeText(this, "You are not connected to the Internet", Toast.LENGTH_LONG).show();
    		hd.postDelayed(new splashHandler(), 1500);
        }  
    }
    
    class splashHandler implements Runnable
    {
    	public void run()
    	{
    		if(cf)
    			startActivity(new Intent(getApplication(), KidsTubeActivity.class));
    		
    		SplashActivity.this.finish();
    	}
    }
}
